<script>
export default {
	async onLaunch() {
		let about = await this.require('getcompanyconfig');
		if (about) {
			for (var i = 0; i < about.length; i++) {
				if (about[i].title === '视频展示') {
					uni.setStorageSync('shipin', about[i].value);
				}
				if (about[i].title === '免责声明') {
					uni.setStorageSync('shenming', about[i].value);
				}
			}
		}
	},
	onShow() {
		uni.removeStorageSync('senderUserId');
		let that = this;
		if (uni.getStorageSync('rong_token')) {
			this.$ry
				.connect({
					token: uni.getStorageSync('rong_token')
				})
				.then(async user => {
					console.log('链接成功, 链接用户 id 为: ', user.id);
					uni.setStorageSync('senderUserId', user.id);
					that.$ry.Conversation.getTotalUnreadCount(false, [1]).then(count => {
						console.log('获取未读总数成功', count);
						uni.setStorageSync('xinxiaoxi', count);
						if (count > 0) {
							uni.showTabBarRedDot({
								index: 3
							});
						} else {
							uni.hideTabBarRedDot({
								index: 3
							})
						}
					});
					await that.require('postrongyunid', { senderUserId: user.id });
					let userInfo = uni.getStorageSync('userInfo');
					uni.setStorageSync(
						'userInfo',
						JSON.stringify({
							...JSON.parse(userInfo),
							senderUserId: user.id
						})
					);
				})
				.catch(error => {
					console.log('链接失败: ', error.code, error.msg);
				});
		}
	},
	onHide() {}
};
</script>

<style lang="scss">
/*每个页面公共css */
@import '@/css/font.css';
@import '@/uni_modules/uview-ui/index.scss';
@import '@/css/ndj.scss';
@import '@/css/flex.scss';
@import '@/css/margin.scss';
</style>
